package com.bit.cfdi.web.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.bit.cfdi.web.dao.DatosFiscalesDAO;
import com.bit.cfdi.web.domain.DatosFiscales;

@Repository
public class DatosFiscalesDAOImpl extends HibernateDaoSupport implements
		DatosFiscalesDAO {

	@Autowired
	public void init(final SessionFactory sessionFactory) throws DataAccessException {
		setSessionFactory(sessionFactory);
	}
	
	@Override
	@Transactional public void save(DatosFiscales datosFiscales) throws DataAccessException {
		getHibernateTemplate().saveOrUpdate(datosFiscales);
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional public DatosFiscales getById(Long id) throws DataAccessException {
		List<DatosFiscales> datosFiscales = getHibernateTemplate().find(
				" from DatosFiscales as df" +
				" where df.idDatosFiscales=?", id);
		return datosFiscales.size()>0?datosFiscales.get(0):null;
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional public List<DatosFiscales> getAll() throws DataAccessException {
		List<DatosFiscales> datosFiscales = getHibernateTemplate().find(
				" from DatosFiscales as df");
		return datosFiscales;
	}

}
